package com.botann.projects.service;

import com.botann.projects.base.BaseService;
import com.botann.projects.model.Version;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * projects
 * VersionService
 * Created by 刘山国 on 2020/5/12.
 * Copyright (c) 2017 伯坦科技. All rights reserved
 */

@Service
public class VersionService extends BaseService implements VersionServiceIntf {
    @Override
    public Class loggerClass() {
        return VersionService.class;
    }

    @Override
    public void addOrUpdate(String json) {
        Version version = jsonToModel(json,Version.class);
        if (version.getUrl() == null) {
            version.setUrl("");
        }
        if (version.getId() <= 0) {
            version.setCreateTime(new Date());
            Version o = sessionGet(Version.class,conditions("name=","del="),version.getName(),false);
            if (o != null) throw sgErrorRuntimeException("构建版本出错啦,版本号重复!");
        }
        version.setUpdateTime(new Date());
        sessionSaveOrUpdate(version);
    }

    @Override
    public void delete(String json) {

    }

    @Override
    public Object loadVersions(Integer pageIndex, Integer pageSize) {
        return sessionQuery(Version.class,pageIndex,pageSize);
    }
}
